# Copyright 2010 G. M. Bond. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.

__author__ = "G. Matthew Bond <gmattbond+python@gmail.com>"

import sys
import gvgen
from . import graph

class GvGraph(graph.Graph):

    """This is an implementation of the Graph class using GvGen."""

    def __init__(self):
        """Set up the graph."""
        self.graph = gvgen.GvGen()

    def add_node(self, node_name):
        """Return a new node with the caption node_name."""
        return self.graph.newItem(node_name)

    def add_edge(self, parent, child):
        """Create and return a new edge between parent and child."""
        return self.graph.newLink(parent, child)

    def output(self, fp=sys.stdout):
        """Output the graph in dot format to the file descriptor fd."""
        return self.graph.dot(fp)
